package scau.zxck.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by lsp on 27/11/2016.
 */
public class PropUtil {
    private static String typePropsFileName = "config/typeMapper.properties";
    private static Properties typeProps;
    private static String basicPropsFileName = "config/basicConfig.properties";
    private static Properties basicProps;

    protected static Properties init(String propFileName) {
        InputStream is = PathUtil.getResourceAsStream(propFileName);
        try {
            Properties props = new Properties();
            props.load(is);
            is.close();
            return props;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getTypeProp(String key) {
        if(typeProps == null){
            typeProps = init(typePropsFileName);
        }
        if(typeProps.containsKey(key)){
            return typeProps.getProperty(key);
        }
        return null;
    }

    public static String getBasicProp(String key) {
        if(basicProps == null){
            basicProps = init(basicPropsFileName);
        }
        if(basicProps.containsKey(key)){
            return basicProps.getProperty(key);
        }
        return null;
    }
}
